#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDebug>
#include <QColorDialog>
#include <QFont>
#include <QFontDialog>
#include <QInputDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

// 选择一个文件
void MainWindow::on_pushButton_clicked()
{
    QString openFileName = QFileDialog::getOpenFileName(this,"选择一个文件","d:/");
    qDebug() << openFileName;
}

// 选择一个文件夹
void MainWindow::on_pushButton_2_clicked()
{
    QString existingDirectory = QFileDialog::getExistingDirectory(this,"选择一个文件夹","./");
    qDebug() << existingDirectory;
}

// 选择多个文件
void MainWindow::on_pushButton_3_clicked()
{
    QStringList openFileNames = QFileDialog::getOpenFileNames(this,"选择多个文件","./");
    if(openFileNames.size()>0){
        QStringListIterator it(openFileNames);
        while (it.hasNext()) {
            QString filename = it.next();
            qDebug() << filename;
        }
    }
}

// 保存文件
void MainWindow::on_pushButton_4_clicked()
{
    QString saveFileName = QFileDialog::getSaveFileName(this,"保存文件名","./");
    qDebug() << saveFileName;
}

void MainWindow::on_pushButton_5_clicked()
{
    QColor color = QColorDialog::getColor();
    QRgb localRgb = color.rgb();
    qDebug() << localRgb;
}

void MainWindow::on_pushButton_6_clicked()
{
    bool ok;
    QFont font = QFontDialog::getFont(&ok);
}

void MainWindow::on_pushButton_7_clicked()
{
    QString text = QInputDialog::getText(this,"输入姓名","name");
    qDebug() << text;
}

void MainWindow::on_pushButton_8_clicked()
{
    int age = QInputDialog::getInt(this,"输入整数","age");
    qDebug() << age;
}

void MainWindow::on_pushButton_9_clicked()
{
    double money = QInputDialog::getDouble(this,"输入小数","money",10.3,-100,100,4);
    qDebug() << money;
}
